﻿CREATE PROCEDURE [dbo].[vk_CompleteList]
	@userId NVARCHAR(128)
AS
BEGIN
	SET @userId = LTRIM(RTRIM(LOWER(@userId)))

	SELECT r1.[PartnerId], r2.[CreateDate]
	FROM [dbo].[vk_Relations] AS r1
	INNER JOIN [dbo].[vk_Relations] AS r2 ON r1.[UserId] = r2.[PartnerId]
	WHERE r1.[UserId] = @userId AND r1.[PartnerId] = r2.[UserId] AND r1.[Complete] = 1 AND r2.[Complete] = 1 AND r1.[Approve] = 0 AND r2.[Approve] = 0
	ORDER BY r1.[CompleteDate] DESC
END
